import App from './App'
import store from './store'

import uView from '@/uni_modules/uview-ui'
Vue.use(uView)

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)
	return {
		app
	}
}
// #endif



const request = (map, data = {}, methods = 'get', header = {}) => {

	//查询本地缓存

	let userData = uni.getStorageSync('userInfo');
	console.log('userData')
	console.log(userData)
	let appid = userData.appid || '';
	let plum_session_applet = userData.plum_session_applet || "";
	
	uni.showLoading({
		title: '加载中...',
		mask: true
	});
	return new Promise((resolve, reject) => {
		uni.request({
			method: methods,
			url: getApp().globalData.base_url+"&map="+map+"&appid="+appid+"&plum_session_applet="+plum_session_applet,
			data: data,
			header: header,
			dataType: 'json',
		}).then((response) => {
			uni.hideLoading();
			let [error, res] = response;
			if(res.data.ec == 400){
				return uni.showToast({
					title:res.data.em,
					icon:"error"
				})
			}
			resolve(res.data);
		}).catch(error => {
			let [err, res] = error;
			reject(err)
		})
	});

}

Vue.prototype.http = request;
Vue.prototype.$store = store;
